package com.web.exiaodao.remote.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

import com.web.webstart.base.constant.XaConstant;
import com.web.webstart.base.controller.BaseController;
import com.web.webstart.base.exception.BusinessException;
import com.web.webstart.base.util.result.XaResult;
import com.web.webstart.base.util.jpa.WebUitl;
import com.web.exiaodao.business.entity.AutherLeaveMessage;
import com.web.exiaodao.remote.service.ApiAutherLeaveMessageService;
import com.web.exiaodao.remote.vo.AutherLeaveMessageVo;

/**
 * @Title: ApiAutherLeaveMessageController.java
 * @Package com.web.exiaodao.remote.controller
 * @Description: 玩/艺术/学乐/达人-留言表信息接口
 * @author wangxuemei  
 * @date 2016-12-14 上午10:23:08
 * @version V1.0
 */
@Api(value = "AutherLeaveMessage", description = "玩/艺术/学乐/达人-留言表接口", position = 10)
@Controller
@RequestMapping("/api/autherLeaveMessage")
public class ApiAutherLeaveMessageController extends BaseController {

	private static final Logger LOGGER = Logger.getLogger(ApiAutherLeaveMessageController.class);

	@Autowired
	private ApiAutherLeaveMessageService autherLeaveMessageService;
	
	/**
	 * @Title: findAutherLeaveMessageList
	 * @Description: 查询所有玩/艺术/学乐/达人-留言表信息
	 * @return    
	 */
	@ApiOperation(value="查询所有玩/艺术/学乐/达人-留言表",notes="查询所有玩/艺术/学乐/达人-留言表信息,当返回的code=1时，取出object进行显示,存放为数组对象")
	@ResponseBody
	@RequestMapping(value="findAutherLeaveMessageList",method=RequestMethod.POST)
	public XaResult<Page<AutherLeaveMessageVo>> findAutherLeaveMessageList(
		@ApiParam("留言ID,字段名:id") @RequestParam(value = "id", required=false) Long id,
		@ApiParam("作品ID,字段名:worksID") @RequestParam(value = "worksID", required=false) Long worksID,
		@ApiParam("页号,字段名:nextPage,默认0,从第0页开始") @RequestParam(defaultValue = "0") Integer nextPage,
		@ApiParam("页长,字段名:pageSize,默认10") @RequestParam(defaultValue = "10") Integer pageSize
	) throws BusinessException{
        XaResult<Page<AutherLeaveMessageVo>> xr = new  XaResult<Page<AutherLeaveMessageVo>>();
		Pageable pageable = WebUitl.buildPageRequest(nextPage, pageSize, "[{property:'createTime',direction:'DESC'}]");
		try{
			AutherLeaveMessageVo autherLeaveMessageVo = new AutherLeaveMessageVo();
			autherLeaveMessageVo.setId(id);
			autherLeaveMessageVo.setWorksID(worksID);
			return autherLeaveMessageService.findAutherLeaveMessageList(pageable,autherLeaveMessageVo);
		}catch(Exception e){
			if (e instanceof BusinessException) {
				xr.error(e.getMessage(), true);
			} else  {
				xr.error(XaConstant.Message.error, true);
			}
			LOGGER.error(XaConstant.Message.error, new Throwable(e));
		}
		return xr;
	}

	
	/**
	 * @Title: findAutherLeaveMessageById
	 * @Description: 根据ID查找单条实体
	 * //@param modelId
	 * @return    
	 */
//	@ApiOperation(value="玩/艺术/学乐/达人-留言表详情",notes="查询玩/艺术/学乐/达人-留言表详细信息,当返回的code=1时，取出object进行显示,存放为单体对象")
//	@ResponseBody
//	@RequestMapping(value="findAutherLeaveMessageById",method=RequestMethod.POST)
//	public XaResult<AutherLeaveMessageVo> findAutherLeaveMessageById(
//		@ApiParam("编号,字段名:id,必填") @RequestParam(value = "id") Long id
//	) throws BusinessException{
//		XaResult<AutherLeaveMessageVo> xr = new XaResult<AutherLeaveMessageVo>();
//		try{
//			return autherLeaveMessageService.findOne(id);
//		}catch(Exception e){
//			if (e instanceof BusinessException) {
//						 xr.error(e.getMessage());
//			} else  {
//				 xr.error(XaConstant.Message.error);
//			}
//			 LOGGER.error(XaConstant.Message.error, new Throwable(e));
//		}
//		return xr;
//	}
	
	/**
	 * @Title: save
	 * @Description: 新增一条实体
	 * //@param userId
	 * //@param model
	 * @return    
	 */
	@ApiOperation(value="新增玩/艺术/学乐/达人-留言表",notes="供前端前期填充数据测试使用,上线后删除;新增玩/艺术/学乐/达人-留言表,当返回的code=1时，保存成功后object返回对象")
	@ResponseBody
	@RequestMapping(value="saveAutherLeaveMessage",method=RequestMethod.POST)
	public XaResult<AutherLeaveMessageVo> saveAutherLeaveMessage(
		@ApiParam("用户id（留言人）,字段名:userId") @RequestParam(value = "userId") Long userId,
		@ApiParam("达人作品id（被留言人）,字段名:worksID") @RequestParam(value = "worksID") Long worksID,
		@ApiParam("留言内容（500字以内）,字段名:leaveMessageContent") @RequestParam(value = "leaveMessageContent") String leaveMessageContent,
		HttpServletRequest request
	) throws BusinessException{
		XaResult<AutherLeaveMessageVo> xr = new XaResult<AutherLeaveMessageVo>();
		try{
		AutherLeaveMessage model = new AutherLeaveMessage();
		model.setLeaveMessageContent(leaveMessageContent);
		model.setUserId(userId);
		model.setWorksID(worksID);
		model.setLeaveMessageContent(leaveMessageContent);
		return autherLeaveMessageService.createModel(model);
		}catch(Exception e){
 			if (e instanceof BusinessException) {
 			    xr.error(e.getMessage());
 			} else  {
 			    xr.error(XaConstant.Message.error);
 			}
 			LOGGER.error(XaConstant.Message.error, new Throwable(e));
		}
		return xr;
	}
	
	/**
	 * @Title: 
	 * @Description: 修改一条实体
	 * //@param userId
	 * //@param model
	 * @return    
	 */
//	@ApiOperation(value="修改玩/艺术/学乐/达人-留言表",notes="修改玩/艺术/学乐/达人-留言表,当返回的code=1时，保存成功后object返回对象")
//	@ResponseBody
//	@RequestMapping(value="updateAutherLeaveMessage",method=RequestMethod.POST)
//	public XaResult<AutherLeaveMessageVo> updateAutherLeaveMessage(
//		@ApiParam("用户id（留言人）,字段名:userId") @RequestParam(value = "userId") Long userId,
//		@ApiParam("达人作品id（被留言人）,字段名:worksID") @RequestParam(value = "worksID") Long worksID,
//		@ApiParam("留言内容（500字以内）,字段名:leaveMessageContent") @RequestParam(value = "leaveMessageContent") String leaveMessageContent,
//		@ApiParam("版本编号,字段名:tId") @RequestParam(value = "tId") Long tId,
//	HttpServletRequest request
//	) throws BusinessException{
//		XaResult<AutherLeaveMessageVo> xr = new XaResult<AutherLeaveMessageVo>();
//		try{
//		AutherLeaveMessage model = new AutherLeaveMessage();
//		model.setLeaveMessageContent(leaveMessageContent);
//		model.setUserId(userId);
//		model.setWorksID(worksID);
//		model.setLeaveMessageContent(leaveMessageContent);
//		model.setId(tId);
//		return autherLeaveMessageService.updateModel(model);
//		}catch(Exception e){
//  			if (e instanceof BusinessException) {
//  			    xr.error(e.getMessage());
//  			} else  {
//  			    xr.error(XaConstant.Message.error);
//  			}
//  			LOGGER.error(XaConstant.Message.error, new Throwable(e));
//		}
//		return xr;
//	}
	
	/**
	 * @Title: operateAutherLeaveMessageById
	 * @Description: 操作一个实体状态,根据status进行操作
	 * @param modelIds
	 * @param status 		操作类型:-1锁定,0无效,1正常,2发布,3删除,默认删除操作
	 * @return    
	 */
//	@ApiOperation(value="根据ID修改玩/艺术/学乐/达人-留言表状态",notes="修改玩/艺术/学乐/达人-留言表状态,当返回的code=1时，保存成功后object返回对象")
//	@ResponseBody
//	@RequestMapping(value="operateAutherLeaveMessageById",method=RequestMethod.POST)
//	public XaResult<AutherLeaveMessageVo> operateAutherLeaveMessageById(
//		HttpServletRequest request,
//		@ApiParam("编号,字段名:modelIds,必填") @RequestParam(value = "modelId") String modelIds,
//		@ApiParam("操作类型,字段名:status,-1锁定,0无效,1正常,2发布,3删除,选填,默认删除操作") @RequestParam(defaultValue = "3") Integer status
//	) throws BusinessException{
//		XaResult<AutherLeaveMessageVo> xr = new XaResult<AutherLeaveMessageVo>();
//		try{
//			return autherLeaveMessageService.multiOperate(modelIds,status);
//		}catch(Exception e){
//  			if (e instanceof BusinessException) {
//  			    xr.error(e.getMessage());
//  			} else  {
//  			    xr.error(XaConstant.Message.error);
//  			}
//  			LOGGER.error(XaConstant.Message.error, new Throwable(e));
//		}
//		return xr;
//	}
	
}

